<%--
  User: Administrator
  Date: 12-3-4
  Time: 下午11:55
--%>

<%@ page pageEncoding="UTF-8" %>
<label>
    <select id="locale-sl">
        <option id="locale-zh-cn" value="zh-CN">中文(简体)</option>
        <%--<option id="locale-zh-tw" value="zh-TW">中文(繁体)</option>--%>
        <option id="locale-en" value="en">English</option>
        <script type="text/javascript">
            var LOCALE_COOKIE_NAME = "html_locale";
            (function () {
                var localeId = "locale-";
                var languageInCookie = getCookie(LOCALE_COOKIE_NAME);
                if (languageInCookie != null && languageInCookie != "") {
                    localeId += languageInCookie.toLowerCase();
                } else {
                    var language = navigator.language ? navigator.language : navigator.userLanguage;
                    language = language.toLowerCase();
                    if (language == "zh-cn" || language == "zh-tw") {
                        localeId += language;
                    } else {
                        localeId += language.split('-')[0];
                    }
                }
                document.getElementById(localeId).selected = "selected";

                function getCookie(name) {
                    var start = document.cookie.indexOf(name);
                    var end = document.cookie.indexOf(";", start);
                    return start == -1 ? '' : decodeURI(document.cookie.substring(start + name.length + 1, (start < end ? end : document.cookie.length)));
                }

            })();

            document.getElementById("locale-sl").onchange = function () {
                if (!this.value) return;
                setLocale(this.value);
                location.reload();

                function setLocale(locale) {
                    var date = new Date();
                    var expireDays = 365;//将date设置为10天以后的时间
                    date.setTime(date.getTime() + expireDays * 24 * 3600 * 1000);
                    document.cookie = LOCALE_COOKIE_NAME + "=" + locale + ";expire=" + date.toGMTString() + ";path=/";
                }
            };
        </script>
    </select>
</label>